<?php namespace app\home\controller;

class Listpage extends Marster{
    //动作
    public function index($cid){
        $article_catgory=Db::table('article')->join('category','cid','=','category_cid')->limit(4)->get(['ctitle','aid','cid','cname','thumb']);
//        p($article_catgory);die;
        View::with('article_catgory',$article_catgory);

        $ctitle=Db::table('article')->orderBy('sendtime','DESC')->orderBy('aid','ASC')->limit(4)->get(['ctitle','sendtime','aid']);
//        p($ctitle);die;
        View::with('ctitle',$ctitle);



        $ccid=Db::table('category')->get();
        $c=$this->findSon($ccid,$cid);
        $c[]=$cid;


        $category=Db::table('article')->join('category','cid','=','category_cid')
            ->whereIn('category_cid',$c)
            ->get();
//        p($category);die;
        View::with('category',$category);
        return view();
    }

    public function findSon($data,$cid){
        static $fonfig=[];
        foreach($data as $k=>$v){
            if($cid==$v['pid']){
                $fonfig[]=$v['cid'];
                $this->findSon($data,$v['cid']);
            }
        }
        return $fonfig;
    }
}
